home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / PIL / PixarImagePlugin.py < prev    next >
Encoding:
Text File  |  2000-06-23  |  1.6 KB  |  72 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id: PixarImagePlugin.py,v 1.1.1.1 1998/08/18 13:07:55 sjoerd Exp $
  4. #
  5. # PIXAR raster support for PIL
  6. #
  7. # history:
  8. #    97-01-29 fl    Created
  9. #
  10. # notes:
  11. #    This is incomplete; it is based on a few samples created with
  12. #    Photoshop 2.5 and 3.0, and a summary description provided by
  13. #    Greg Coats <gcoats@labiris.er.usgs.gov>.  Hopefully, "L" and
  14. #    "RGBA" support will be added in future versions.
  15. #
  16. # Copyright (c) Secret Labs AB 1997.
  17. # Copyright (c) Fredrik Lundh 1997.
  18. #
  19. # See the README file for information on usage and redistribution.
  20. #
  21.  
  22. __version__ = "0.1"
  23.  
  24. import Image, ImageFile
  25.  
  26. #
  27. # helpers
  28.  
  29. def i16(c):
  30.     return ord(c[0]) + (ord(c[1])<<8)
  31.  
  32. def i32(c):
  33.     return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24)
  34.  
  35. #
  36. # --------------------------------------------------------------------
  37.  
  38. class PixarImageFile(ImageFile.ImageFile):
  39.  
  40.     format = "PIXAR"
  41.     format_description = "PIXAR raster image"
  42.  
  43.     def _open(self):
  44.  
  45.     # assuming a 4-byte magic label (FIXME: add "_accept" hook)
  46.     s = self.fp.read(4)
  47.     if s != "\200\350\000\000":
  48.         raise SyntaxError, "not a PIXAR file"
  49.  
  50.     # read rest of header
  51.     s = s + self.fp.read(508)
  52.  
  53.     self.size = i16(s[418:420]), i16(s[416:418])
  54.  
  55.     # get channel/depth descriptions
  56.     mode = i16(s[424:426]), i16(s[426:428])
  57.  
  58.     if mode == (14, 2):
  59.         self.mode = "RGB"
  60.     # FIXME: to be continued...
  61.  
  62.     # create tile descriptor (assuming "dumped")
  63.     self.tile = [("raw", (0,0)+self.size, 1024, (self.mode, 0, 1))]
  64.  
  65. #
  66. # --------------------------------------------------------------------
  67.  
  68. Image.register_open("PIXAR", PixarImageFile)
  69.  
  70. #
  71. # FIXME: what's the standard extension?
  72.